<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class CorePerson {

    protected $mPersonId;
    protected $mNamaLengkap;
    protected $mKategori;
    protected $mAgama;
    protected $mGolDarah;
    protected $mGolDarahId;
    protected $mKelamin;
    protected $mKelaminId;
    protected $mAlamat;
    protected $mTelepon;

    public function __construct($pPersonId = null) {
        $this->mPersonId = $pPersonId;
        $this->GetDetailPerson();
    }

    

    public function GeneratePersonId($pPersonKategori) {
        $mQuery = new DBQueryParse();
        $tTahun= date("y");
        $tBulan= date("m");
        
        $tSQL = "SELECT MAX(id_person) as id FROM app_person WHERE id_person LIKE \"" . $pPersonKategori . "-".$tTahun."%\"";
        //$tSQL = "SELECT MAX(id_person) as id FROM app_person WHERE id_person LIKE \"" . $pPersonKategori . "-".$tTahun."".$tBulan."%\"";
        $tRes = $mQuery->Execute($tSQL);

        if ($tRes->MoveFirst() && $tRes->id != NULL) {
            //JIKA TELAH ADA
            $tId = $tRes->id;
            $tTemp= explode("-",$tId);
            $tTemp[1]++;
            
            $tResult= $tTemp[0]."-".$tTemp[1];
        } else {
            //$tResult = $pPersonKategori . "-".$tTahun."".$tBulan. "001";
            $tResult = $pPersonKategori . "-".$tTahun."00001";
        }
        return $tResult;
    }

    public function GetTanggalLahir() {
        $mData = new DBQueryParse();
        $tSQL = 'SELECT DATE_FORMAT(tanggal_lahir, "%d%m%Y") as tanggal_lahir FROM app_person WHERE id_person= \'' . $this->mPersonId . '\' ';
        //echo $tSQL;
        $tRes = $mData->Execute($tSQL);

        if ($tRes->MoveFirst())
            return $tRes->tanggal_lahir;
        else
            return false;
    }

    public function GetEmail() {
        $mData = new DBQueryParse();
        $tSQL = 'SELECT email FROM app_person WHERE id_person= \'' . $this->mPersonId . '\' ';
        //echo $tSQL;
        $tRes = $mData->Execute($tSQL);

        if ($tRes->MoveFirst())
            return $tRes->email;
        else
            return false;
    }

    public function GetListKategori() {
        $mQuery = new DBQueryParse();
        $tResult = array();

        $tSQL = "SELECT id_kategori as id, nama_kategori as value FROM app_person_kategori ORDER BY nama_kategori";
        $tRes = $mQuery->Execute($tSQL);

        if ($tRes->Count() > 0) {
            return $tRes;
        } else {
            return false;
        }
    }

    // MUTUATOR
    public function SetPersonId($pPersonId){
        $this->mPersonId= $pPersonId;
    }
    
    public function GetDetailPerson() {
        $mQuery = new DBQueryParse();
        $tSQL = "SELECT nama_lengkap, kategori, agama, goldarah, goldarah_id, kelamin, kelamin_id, alamat, telepon FROM view_app_person WHERE id_person = \"" . $this->mPersonId . "\"";
        $tRes = $mQuery->Execute($tSQL);
        //echo $tSQL;
        if ($tRes->Count() > 0) {
            $tRes->MoveFirst();
            $this->mNamaLengkap = $tRes->nama_lengkap;
            $this->mKategori = $tRes->kategori;
            $this->mAgama = $tRes->agama;
            $this->mGolDarah = $tRes->goldarah;
            $this->mGolDarahId = $tRes->goldarah_id;
            $this->mKelamin = $tRes->kelamin;
            $this->mKelaminId = $tRes->kelamin;
            $this->mAlamat = $tRes->alamat;
            $this->mTelepon = $tRes->telepon;
        } else {
            return false;
        }
    }
    
        
    public function GetPersonId() {
        return $this->mPersonId;
    }
    
    public function GetNamaLengkap() {
        return $this->mNamaLengkap;
    }

    public function GetAgama() {
        return $this->mAgama;
    }

    public function GetGolDarah() {
        return $this->mGolDarah;
    }

    public function GetGolDarahId() {
        return $this->mGolDarahId;
    }
    
    public function GetKelamin() {
        return $this->mKelamin;
    }
    
    public function GetKelaminId() {
        return $this->mKelaminId;
    }
    
    public function GetAlamat() {
        return $this->mAlamat;
    }
    
    public function GetTelepon() {
        return $this->mTelepon;
    }
    
}

?>
